package com.xiaorong.util;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.io.SAXReader;
import org.springframework.core.io.ClassPathResource;

import com.xiaorong.entity.LogConfig;

/**
 * 用于读取权限配置文件
 * @author LV_FQ
 *
 */
@SuppressWarnings("unchecked")
public class LogConfigUtils {
	
	private LogConfigUtils(){
	};
	
	private static List<LogConfig> logConfigs = new ArrayList<LogConfig>();
	
	static {
		try {
			File xmlFile = new ClassPathResource("/xiaorong.xml").getFile();
			Document document = new SAXReader().read(xmlFile);
			List<org.dom4j.Element> elements = document.selectNodes("/xiaorong/logConfig");
			for (org.dom4j.Element element : elements) {
				String operation = element.attributeValue("operation");
				String urlPattern = element.attributeValue("urlPattern");
				String auth = element.attributeValue("auth");
				LogConfig logConfig = new LogConfig();
				logConfig.setOperation(operation);
				logConfig.setUrlPattern(urlPattern);
				logConfig.setAuth(auth);
				logConfigs.add(logConfig);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	
	public static List<LogConfig> getAll() {
		return logConfigs;
	}
}
